package com.duanjw.springboot.amqp;

import static com.duanjw.springboot.amqp.QueueConfig.QUEUE_NAME;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import lombok.AllArgsConstructor;

/**
 * 消息
 *
 * @author duanjw
 * @since 2022/3/30
 */
@RestController
@RequestMapping("message")
@AllArgsConstructor
public class MessageController {

    private final AmqpTemplate amqpTemplate;

    /**
     * 往 mq 发送消息
     * curl -X POST localhost:8080/message/hello
     * @param msg 消息内容
     */
    @PostMapping("{msg}")
    public boolean sendMessage(@PathVariable String msg) {
        amqpTemplate.convertAndSend(QUEUE_NAME, msg);
        return true;
    }
}
